<!-- 我的 – 基本信息		basic -->
<template>
	<view class="pb40">
		<view class="basic-box pt5 pb10">
			<view class="w90" style="padding-top:22rpx;">
				<view class=" f flex-between c" @click="shangchuan">
					<text class="fs28">头像：</text>
					<view class="dis-flex flex-between ">
						<view class="mr10">
							<image :src="img " mode="" style="width: 80rpx;height: 80rpx;border-radius: 200rpx;">
							</image>
						</view>
						<u-icon name="arrow-right" color="#a1a1a1" size="24"></u-icon>
					</view>
				</view>
				<view class="quanxian m_t_30"></view>
			</view>
			<view class="w90" style="padding-top:22rpx;">
				<view class=" f flex-between c">
					<text class="fs28">姓名：</text>
					<u-input v-model="name" type="text" placeholder="请输入姓名" :border="false" :clearable="false" input-align="right"/>
				</view>
				<view class="quanxian m_t_30"></view>
			</view>
		<!-- 	<view class="w90" style="padding-top:22rpx;">
				<view class=" f  c flex-between" >
					<text class="fs28">年龄：</text>
					<u-input v-model="age" type="number" placeholder="请输入年龄" :border="false" :clearable="false" input-align="right"/>
				</view>
				<view class="quanxian m_t_30"></view>
			</view> -->
			<view class="w90" style="padding-top:22rpx;">
				<view class=" f  c flex-between" @click="showAction">
					<text class="fs28">性别：</text>
					<text class="fs28 c-666">{{sex?sex:'请选择性别'}}</text>
				</view>
				<view class="quanxian m_t_30"></view>
			</view>
			<view class="w90" style="padding-top:22rpx;">
				<view class=" f  c flex-between" @click="goshengri">
					<text class="fs28">生日：</text>
					<text class="fs28 c-666">{{birthday?birthday:"请选择生日"}}</text>
				</view>
				<view class=" m_t_30"></view>
			</view>
		</view>
		<view class="basic-box pt5 pb10">
			<view class="w90" style="padding-top:22rpx;">
				<view class=" f  c flex-between">
					<text class="fs28">手机号：</text>
					<text class="fs28 c-666">{{data.phone}}</text>
				</view>
				<view class="quanxian m_t_30"></view>
			</view>
			<view class="w90" style="padding-top:22rpx;">
				<view class=" f  c flex-between">
					<text class="fs28">加入时间：</text>
					<text class="fs28 c-666">{{data.create_time | fengetime}}</text>
				</view>
				<view class="quanxian m_t_30"></view>
			</view>
			<view class="w90" style="padding-top:22rpx;">
				<view class=" f  c flex-between">
					<text class="fs28">我的积分：</text>
					<text class="fs28 c-666">{{data.integral}}</text>
				</view>
				<view class=" m_t_30"></view>
			</view>
		</view>
		<view class="mt50">
			<view class="text-area mb10 " @click="qiehuan" v-if="is_duoUser">
				<view class="but center" style="background-color: #E0E0E0">切换用户</view>
			</view>
			<view class="text-area " @click="xiugai">
				<view class="but center">修改</view>
			</view>
		</view>
		
		<u-action-sheet @click="clickItem" :list="sexList" v-model="sex_show"></u-action-sheet>
		<u-calendar v-model="sr_show" mode="date" @change="change"></u-calendar>
		<u-popup v-model="show" mode="center" width="80%" border-radius="20">
			<view class="center" >
				<view class="bb" style="height: 100rpx;line-height: 100rpx;">
					选择用户
				</view>
				<view class=" pb20 dis-flex flex-wrap">
					<view @click="gouser(item)" class="wd50 mt20" v-for="(item,index) in userList">
						<image :src="item.img" mode="" style="border-radius: 200rpx;width: 130rpx;height: 130rpx;"></image>
						<view class="c-999 fs26 mt5 ellipsis pl20 pr20">
							{{item.name}}
						</view>
					</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				loginResCode:'',
				show:false,
				userList:[],
				sex_show:false,
				sr_show:false,
				sexList: [
					{
						text: '男',
					},
					{
						text: '女'
					}
				],
				data: [],
				img: '',
				name:'',
				sex:'',
				birthday:'',
				is_duoUser:false
			}
		},
		onLoad(e) {
			// 动态导航条文字
			uni.setNavigationBarTitle({
				title: '基本信息'
			})
			this.data = JSON.parse(decodeURIComponent(e.data));
			this.img = this.data.img
			this.name = this.data.name
			this.sex = this.data.sex
			this.birthday = this.data.birthday
			this.init()
		},
		methods: {
			init(){
				var that = this
				var json={
					token: uni.getStorageSync('token'),
				}
				that.$http.post(that.$config.UrlPostuserList, json).then((res) => {
					if (res.status == 1 && res.data.length > 1) {
						that.is_duoUser = true
						that.userList = res.data
					}
				})
			},
			//图片上传
			shangchuan() {
				var that = this
				uni.chooseImage({
					count: 1,
					sizeType: 'compressed',
					success: (res) => {
						const imgsFile = res.tempFilePaths
						//上传
						const uper = uni.uploadFile({
							url: that.$config.hosts + that.$config.UrlPostgetfile,
							filePath: imgsFile[0],
							name: 'file',
							// formData:{    },用于做令牌认证
							success: function(res1) {
								if (res1.statusCode == 200) {
									let data = JSON.parse(res1.data)
									that.img = data.data
								}
							}
						})

					}
				})
			},
			xiugai() {
				var that = this
				var json={
					img: that.img,
					name:that.name,
					sex:that.sex,
					birthday:that.birthday
				}
				that.$http.post(that.$config.UrlPosteditInfo, json).then((res) => {
					if (res.status == 1 ) {
						that.$api.toast('修改成功')
					}
				})
			},
			showAction() {
				this.sex_show = true;
			},
			clickItem(index) {
				this.sex = this.sexList[index].text;
			},
			goshengri(){
				this.sr_show = !this.sr_show
			},
			change(e){
				this.birthday = e.result
			},
			//选择用户
			gouser(item){
				var that = this
				uni.login({
					provider: 'weixin',
					success: function(loginRes) {
						var json={
							code: loginRes.code,
							token:item.token
						}
						that.$http.post(that.$config.UrlPostselectUser, json).then((res) => {
							if (res.status == 1 ) {
								uni.setStorageSync('token', item.token);
								that.$api.toast('切换成功')
								setTimeout(()=>{
									that.$api.openWindow('/pages/mine/mine','switchTab')
								},500)
							}
						})
					}
				});
			},
			qiehuan(){
				this.show = !this.show
			}
		}
	}
</script>

<style scoped>
	.warps {
		height: 95vh;
		overflow: hidden;
		background-color: #F6F8FC;
	}

	.basic-box {
		width: 686rpx;
		opacity: 1;
		background: #ffffff;
		border-radius: 16rpx;
		box-shadow: 0rpx 0rpx 12rpx 0rpx rgba(0, 0, 0, 0.16);
		margin: 0 auto;
		margin-top: 32rpx;
	}

	.ipts {
		width: 200rpx;
		height: 34rpx;
		font-size: 24rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.but {
		width: 600rpx;
		height: 76rpx;
		line-height: 76rpx;
		opacity: 1;
		background: #1f73f2;
		border-radius: 16rpx;
		font-size: 28rpx;
		color: #fff;
	}
</style>
